home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / dvivga9.zip / OPTION.H < prev    next >
C/C++ Source or Header  |  1988-08-12  |  8KB  |  349 lines

  1. /* -*-C-*- option.h */
  2. /*-->option*/
  3. /**********************************************************************/
  4. /******************************* option *******************************/
  5. /**********************************************************************/
  6.  
  7. void
  8. option(optstr)            /* process command-line option */
  9. char *optstr;            /* option string (e.g. "-m1500") */
  10. {
  11.     register UNSIGN32 k;    /* magnification */
  12.     register int value;        /* converted digit string value */
  13.     register int m;        /* loop index */
  14.     char *p;            /* pointer into optstr */
  15.     int p1,p2,p3;        /* temp values for sscanf() */
  16.     double fltmag;        /* floating-point mag value */
  17.  
  18.     typedef struct
  19.     {
  20.     char* envname;
  21.     char* envvar;
  22.     } envstruct;
  23.  
  24.     static envstruct envlist[] =
  25.     {    /* names and addresses of environment vars (alphabetical order) */
  26.     "DVIHELP",    helpcmd,
  27.     "FONTLIST",    fontlist,
  28.     "TEXFONTS",    fontpath,
  29.     "TEXINPUTS",    subpath,
  30.     };
  31.  
  32.     if (*optstr != '-')
  33.     return;            /* return if this is not an option */
  34.  
  35.     switch (*(optstr+1))
  36.     {
  37.  
  38.     case 'a':    /* A selects virtual font caching */
  39.     case 'A':
  40.  
  41. #if    VIRTUAL_FONTS
  42.     virt_font = TRUE;
  43. #endif
  44.     break;
  45.  
  46.     case 'b':    /* b selects backwards printing order */
  47.     case 'B':
  48.     backwards = TRUE;
  49.     break;
  50.  
  51. #if (!VGASCREEN)
  52.     case 'c':    /* c selects number of copies */
  53.     case 'C':
  54.     copies = (UNSIGN16) atoi(optstr+2);
  55.     copies = MAX(1,MIN(copies,256)); /* enforce reasonable limits */
  56.     break;
  57. #endif
  58.  
  59.     case 'd':    /* d selects debug output */
  60.     case 'D':
  61.     debug_code |= (BYTE)atoi(optstr+2);
  62.     break;
  63.  
  64.  
  65.     case 'e':    /* e specifies ``environment'' variable definition */
  66.     case 'E':    /* We ignore letter case since these come from */
  67.         /* the command line */
  68.     if (!(p = strrchr(optstr,'=')))
  69.     {
  70.         (void)usage(stderr);
  71.         (void)sprintf(message,
  72.             "option():  Bad switch [%s]--expected -eENVNAME=value",
  73.         optstr);
  74.         (void)fatal(message);
  75.     }
  76.     *p = '\0';        /* clobber "=" by string terminator */
  77.     for (m = 0; m < sizeof(envlist)/sizeof(envlist[0]); ++m)
  78.     {
  79.         if (strcm2(optstr+2,envlist[m].envname) == 0)
  80.         {
  81.         (void)strcpy(envlist[m].envvar,p+1);
  82.         return;
  83.         }
  84.     }
  85.     (void)usage(stderr);
  86.  
  87.     (void)sprintf(message,"option():  Bad switch [%s]--expected one of:",
  88.         optstr);
  89.     for (m = 0; m < sizeof(envlist)/sizeof(envlist[0]); ++m)
  90.     {
  91.         (void)strcat(message," ");
  92.         (void)strcat(message,envlist[m].envname);
  93.     }
  94.     (void)fatal(message);
  95.     break;
  96.  
  97.  
  98.     case 'f':    /* f specifies font substitution file */
  99.     case 'F':
  100.     (void)strcpy(subfile,optstr+2);
  101.     break;
  102.  
  103.  
  104. #if    CANON_A2
  105.  
  106. #ifdef CANON_TEST
  107.     case 'g':
  108.     case 'G':
  109.         stor_fonts = (UNSIGN32)atoi(optstr + 2 );
  110.         break;
  111. #endif /* CANON_TEST */
  112.  
  113. #endif
  114.  
  115.     case 'l':    /* l prohibits logging of errors */
  116.     case 'L':
  117.     g_dolog = FALSE;
  118.     break;
  119.  
  120.  
  121.     case 'm':    /* m selects alternate magnification */
  122.     case 'M':
  123.     /* Collect 2*value initially.  Then if value is small, assume
  124.     user specified magstep value; magstep k means 1.2**k, where k
  125.     is integral, or half-integral.  Otherwise, assume user has
  126.     specified pxl file magnification (1000 == 200dpi, 1500 ==
  127.     300dpi, etc.).  */
  128.  
  129.  
  130.     if (strchr(optstr+2,'.') != (char *)NULL)
  131.         fltmag = (double)(2.0 * atof(optstr+2));
  132.     else
  133.         fltmag = (double)(2 * atoi(optstr+2));
  134.     if ((0.0 != fltmag) && 
  135.         (-30.0 <= fltmag) && (fltmag <= 30.0)) /* magstep 15 is limit */
  136.     {
  137.         if (fltmag < 0.0)
  138.             runmag = (UNSIGN32)(0.5 + 
  139.             (1.0/pow((double)sqrt(1.2),-fltmag))*(double)STDMAG);
  140.         else
  141.             runmag = (UNSIGN32)(0.5 + pow((double)sqrt(1.2),fltmag)*
  142.                 (double)STDMAG);
  143.     }
  144.     else
  145.         runmag = (UNSIGN32)(0.5 + fltmag/2.0);
  146.  
  147.     k = MAGSIZE(actfact(runmag));  /* rounded magnification */
  148.     if (k != runmag)
  149.     {
  150.         (void)sprintf(message,
  151.         "option():  Requested magnification %d not available.",
  152.         (int)runmag);
  153.         (void)warning(message);
  154.         runmag = k;
  155.         k = (UNSIGN32) MAX(1,MIN(mag_index,(MAGTABSIZE-1)));
  156.         (void)sprintf(message,
  157.         "  Magnification reset to nearest legal value %d in \
  158. family ..%d..%d..%d..",
  159.         (int)runmag,(int)MAGSIZE(mag_table[k-1]),
  160.         (int)MAGSIZE(mag_table[k]),
  161.         (int)MAGSIZE(mag_table[k+1]));
  162.         (void)warning(message);
  163.     }
  164.     break;
  165.  
  166. #if  (!VGASCREEN) 
  167.     case 'o':
  168.     case 'O':    /* o selects output page range (-o# or -o#:# or -o#:#:#) */
  169.         p1 = p2 = p3 = 0;
  170.     value = (int)sscanf(optstr+2,"%d:%d:%d",&p1,&p2,&p3);
  171.     page_begin[npage] = p1;
  172.     page_end[npage] = p2;
  173.     page_step[npage] = p3;
  174.     switch (value)
  175.     {
  176.     case 1:
  177.         optstr++;            /* point past "-" */
  178.  
  179.         do                /* skip over digit string */
  180.         {
  181.         optstr++;
  182.         }
  183.         while (isdigit(*optstr) || (*optstr == '-') || (*optstr == '+'));
  184.  
  185.         if (*optstr)        /* trash follows number */
  186.         {
  187.             (void)usage(stderr);
  188.         (void)sprintf(message,
  189.             "option():  %s is not a legal page number switch",optstr);
  190.         (void)fatal(message);
  191.         }
  192.         else            /* had expected end-of-string */
  193.             page_end[npage] = (INT16)page_begin[npage];
  194.         page_step[npage] = 1;
  195.         break;
  196.  
  197.     case 2:        /* supply default step */
  198.         page_step[npage] = 1;
  199.         /* FALL THROUGH to case 3 for order check */
  200.  
  201.     case 3:        /* check for positive step */
  202.         page_step[npage] = ABS(page_step[npage]);
  203.         if (page_step[npage] == 0)
  204.         page_step[npage] = 1;
  205.         break;
  206.  
  207.     default:    /* illegal value */
  208.         (void)usage(stderr);
  209.         (void)sprintf(message,
  210.         "option():  %s is not a legal page number switch",optstr);
  211.         (void)fatal(message);
  212.     }
  213.     npage++;
  214.     break;
  215. #endif    /* VGASCREEN */
  216.  
  217.  
  218.     case 'p':    /* p prohibits pre-font loading */
  219.     case 'P':
  220. #if    (HPLASERJET|HPJETPLUS|GOLDENDAWNGL100|POSTSCRIPT|IMPRESS|CANON_A2|VGASCREEN)
  221.     preload = TRUE;    /* preloading required for Canon engines */
  222.             /* because of reverse printing order */
  223. #else
  224.     preload = FALSE;
  225. #endif /*NOT(HPLASERJET|HPJETPLUS|GOLDENDAWNGL100|POSTSCRIPT|IMPRESS|CANON_A2|VGASCREEN)*/
  226.     break;
  227.  
  228.  
  229.     case 'q':    /* q inhibits status display */
  230.     case 'Q':
  231. #if VGASCREEN
  232.         quiet = FALSE;
  233. #else
  234.     quiet = TRUE;
  235. #endif
  236.     break;
  237.  
  238.  
  239. #if    HPLASERJET
  240.     case 'r':    /* r selects output resolution */
  241.     case 'R':
  242.     hpres = (INT16)atoi(optstr+2);
  243.     if ((hpres != 75) && (hpres != 100) && (hpres != 150) &&
  244.         (hpres != 300))
  245.         {
  246.         (void)sprintf(message,
  247.         "option():  Output resolution not in [75,100,150,300] dpi; \
  248. reset to %d",
  249.         DEFAULT_RESOLUTION);
  250.         (void)warning(message);
  251.         hpres = DEFAULT_RESOLUTION;
  252.         }
  253.     break;
  254. #endif /* HPLASERJET */
  255.  
  256.  
  257. #if    (APPLEIMAGEWRITER | EPSON | GOLDENDAWNGL100 | TOSHIBAP1351)
  258.     case 'r':    /* r selects run-length coding of output */
  259.     case 'R':
  260.     runlengthcode = TRUE;
  261.     break;
  262. #endif /* (APPLEIMAGEWRITER | EPSON | GOLDENDAWNGL100 | TOSHIBAP1351) */
  263.  
  264. #if    VGASCREEN
  265.     case 'r':
  266.     case 'R':
  267.         reversevideo = TRUE;
  268.         break;
  269. #endif /* VGASCREEN */
  270.  
  271. #if    CANON_A2
  272.  
  273. #ifdef CANON_TEST
  274.     case 's':    /* pixel size limit to force character reloading */
  275.     case 'S':
  276.     size_limit = (UNSIGN16)atoi(optstr+2);
  277.     break;
  278. #endif /* CANON_TEST */
  279.  
  280. #endif /* CANON_A2 */
  281.  
  282. #if    POSTSCRIPT
  283.     case 's':    /* pixel size limit to force character reloading */
  284.     case 'S':
  285.     size_limit = (UNSIGN16)atoi(optstr+2);
  286.     break;
  287. #endif
  288.  
  289. #if    EPSON
  290.     case 't':
  291.     case 'T':
  292.  
  293. #if    HIRES
  294.     twice_a_line = TRUE;
  295. #endif /* HIRES */
  296.  
  297.     break;
  298. #endif /* EPSON */
  299.  
  300.  
  301. #if    CANON_A2
  302.  
  303. #ifdef CANON_TEST
  304.     case 'u':
  305.     case 'U':
  306.     merit_fact = (UNSIGN16)atoi(optstr+2);
  307.     break;
  308.  
  309.     case 'v':
  310.     case 'V':
  311.     stor_limit = (UNSIGN32)atoi(optstr+2);
  312.     break;
  313. #endif /* CANON_TEST */
  314.  
  315. #endif /* CANON_A2 */
  316.  
  317. #if    POSTSCRIPT
  318.     case 'v':    /* vmbug -- reload fonts on each page */
  319.     case 'V':
  320.     ps_vmbug = TRUE;
  321.     break;
  322. #endif /* POSTSCRIPT */
  323.  
  324.  
  325.     case 'x':
  326.     case 'X':
  327.     leftmargin = inch(optstr+2);
  328.     break;
  329.  
  330.  
  331.     case 'y':
  332.     case 'Y':
  333.     topmargin = inch(optstr+2);
  334.     break;
  335.  
  336. #if    (OS_TOPS20 | BSD42)
  337.     case 'z':
  338.     case 'Z':
  339.     spool_output = TRUE;    /* offer to